﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ESHOP.Domain;
namespace ESHOP.DAO
{
     public class NhanvienDAO :BaseDAO
    {
         public NHANVIEN    Get(string ma)
        {
            return _db.NHANVIENs.SingleOrDefault(p => p.ID.Equals(ma));
        }

        public List<NHANVIEN> Search(string key)
        {
            return _db.NHANVIENs.Where(p => p.TENNV.ToUpper().Contains(key.ToUpper())
                || p.ID.ToUpper().Contains(key.ToUpper()) )
                    .ToList();
        }
        public List<NHANVIEN> GetList()
        {
            return _db.NHANVIENs.ToList();
        }

       
        public List<NHANVIEN> GetList(int fromIndex, int toIndex)
        {
            return GetList().Skip(fromIndex).Take(toIndex - fromIndex).ToList();
        }

        public int Count( )
        {
            return _db.NHANVIENs.Count();
        }

        public int Insert(NHANVIEN objUi)
        {
           
            try
            {

                _db.Connection.Open();

                _db.NHANVIENs.InsertOnSubmit(objUi);
                _db.SubmitChanges();

                // commit

                // success message
                return 1;
            }
            catch (Exception ex)
            {
                // rollback transaction

                return 0;
            }
            return 1;
        }

       

       

       

    }

    public class NHANVIENTT
    {
        public string MANV { get; set; }
        public string HOTEN { get; set; }
        public int? MATT { get; set; }

        public NHANVIENTT()
        {

        }

        public NHANVIENTT(string manv, string tennv, int? matt)
        {
            MANV = manv;
            HOTEN = tennv;
            MATT = matt;
        }
    }

    public class NHANVIENTG
    {
        public string MANV { get; set; }
        public string HOTEN { get; set; }
        public int? MATG { get; set; }

        public NHANVIENTG()
        {
            
        }

        public NHANVIENTG(string manv, string tennv, int? matg)
        {
            MANV = manv;
            HOTEN = tennv;
            MATG = matg;
        }
    }
    
}
